package juc;

import java.util.Scanner;

public class practice1 {
    public static void main(String[] args) {
        A a = new A();
        B b = new B(a);
        a.start();
        b.start();
    }
}

class A extends Thread {
    private boolean loop = true;
    @Override
    public void run(){
        // output 1 - 100
        while (loop) {
            System.out.println((int) (Math.random() * 100 + 1));
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

    }

    public void setLoop(boolean loop) {
        this.loop = loop;
    }
}

class B extends Thread {
    private A a;
    private final Scanner scanner = new Scanner(System.in);
    public B(A a){
        this.a = a;
    }

    @Override
    public void run() {
        while(true) {
            System.out.println("Input: Q to stop thread");
            char s = scanner.next().toUpperCase().charAt(0);
            if(s == 'Q'){
                a.setLoop(false);
                break;
            }
        }
    }
}